<?php
    require_once('../includes/DbConnector.php');
    
    if(isset($_GET['action']) && !empty($_GET['action'])) {
        // INPUT DATA.
        $action = $_GET['action'];
        $connector  = new DbConnector();
        $sql = "select
                b.*,
                p.name place,
                c.name country,
                (select avg(ub.rating) from user_bar ub where ub.bar_id = b.bar_id) rating
                from bar b, place p, country c
                where b.postal_no = p.postal_no
                and p.country_code = c.country_code
                and b.status_id = 1
                order by cover_charge, beer_price, rating desc
                limit 10";
        $result = $connector->query($sql);
        
        $a=array();
        while($row = mysql_fetch_array($result)){
            array_push($a,$row);
        }
        
        echo json_encode($a);
    }
?>